$(function () {

    //初始化加载datagrid
    $('#dg1').datagrid({
        method: 'post',
        url: ROOT_PATH + '/workflow/flowManagement/findWorkItemList.shtml',
        queryParams: {
         sort: 'createdTime',
         order: 'desc',
         queryState:1
         },
        //idField: 'id',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        sortOrder: true,
        striped: true,
        fit: true,
        columns: [[
            {field: 'id', width: 80, checkbox: true},
            {field: 'flowDisplayName', title: '业务流程', width: 80, sortable: true},
            {field: 'taskDisplayName', title: '流程环节', width: 80, sortable: true,
                formatter: function (value, row, index) {
                    var returnStr="<a onclick=\"flowMonitorByWorkItemId('"+row.id+"')\" style='color:blue;'>";
                    returnStr+=value;
                    returnStr+="</a>";
                    return returnStr;
                }},
            {field: 'businessContent', title: '业务描述', width: 80, sortable: true},
            {field: 'state', title: '状态', width: 100, sortable: true,
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return '未签收';
                    } else {
                        return '已签收';
                    }
                }},
            {field: 'createdTime', title: '接收时间', width: 80, sortable: true},

        ]]
    });
    $('#btn_search').on("click", function () {
        var params=$('#tb1').find(':input').serializeJson();
        params.sort='createdTime';
        params.order='desc';
        $('#dg1').datagrid('load',params);
    });

    /***
     * 待办审批
     * @returns {boolean}
     */
    $('#btn_workflow_verify').on('click',function () {
        var $selected = $('#dg1').datagrid('getSelections');
        if ($selected.length != 1) {
            layer.alert('请选择一条待办！');
            return false;
        }
        var workItemId=$selected[0].id;//工作项id
        //打开业务表单
        WindowManager.openLayer({
            type: 2,
            title: '业务审批',
            area: ['1150px', '80%'],
            content: ROOT_PATH +"/workflow/flowManagement/toBusinessPage.shtml?workItemId="+workItemId+"&formType=1",
            end:function(){
                $('#dg1').datagrid('reload');//刷新列表
            }
        });
    });
});


